package com.shao.im.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.shao.im.entity.Post;
import com.shao.im.entity.vo.PostListVo;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 动态表(Post)表数据库访问层
 *
 * @author makejava
 * @since 2023-08-04 22:23:23
 */
public interface PostDao extends BaseMapper<Post> {

    @Select("""
            select distinct p.pid, u.id fid, if(fr.beizhu,fr.beizhu , u.nickname) nickname, u.header, p.content, p.create_time
            	from post p
            	join user u on p.uid = u.id
            	join friends_request fr on u.id = fr.uid
            	where fr.uid = #{uid} or fr.uid in
            		(
            			select fid from friends_relations where uid = #{uid}
            		)
            	order by p.create_time desc
                """)
    List<PostListVo> queryPostList(Integer uid);
}

